home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / lan / nbsamp.arc / NBSEND2.C < prev    next >
Text File  |  1988-09-26  |  3KB  |  100 lines

  1. /* NBSEND2.C - test of NetBIOS- sends a datagram    - Paul McGinnis   */
  2. /* AST Research, Inc. - Data Comm Support - Dept. 430                 */
  3. /* September 1988. - comments added 9/26/88                           */
  4. /*                                      */
  5. /* General calling sequence for NetBIOS calls:                        */
  6. /* 1. Set up NCB (Network Control Block)                              */
  7. /* 2. Make ES:BX point to NCB structure                               */
  8. /* 3. Load AX with 100h                                               */
  9. /* 4. Generate an INT 5Ch                                             */
  10. /*                                       */
  11. /* NetBIOS commands and definitions in NETBIOS.H                      */
  12. /*                                      */
  13. /* Compilation information:                                           */
  14. /* Compiler: Borland Turbo C v1.5                                     */
  15. /* Memory model: Small                                                */
  16. /* Floating point support: none                                       */
  17.  
  18.  
  19. #include <dos.h>
  20. #include <stdio.h>
  21. #include <netbios.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24.  
  25.  
  26. main()
  27. {
  28.   NCB * send_block;
  29.   char * send_message;
  30.   char * session;
  31.   char * rcvr;
  32.   unsigned char ret_code, net_num, iflag;
  33.   send_block = (NCB *) malloc(sizeof(NCB));
  34.   send_message = (char *) malloc(80);
  35.   session = (char *) malloc(16);
  36.   rcvr = (char *) malloc(16);
  37.   _AH = 0;
  38.   geninterrupt(0x2a);   /* Check to see if NetBIOS is loaded */
  39.   iflag = _AH;
  40.   if (!iflag)
  41.   {
  42.     puts("    *** ERROR - NetBIOS not installed. ***");
  43.     return;
  44.   }
  45.   printf("Enter session name: ");
  46.   gets(session);
  47.   printf("Enter receiver's name: ");
  48.   gets(rcvr);
  49.   printf("Enter message: ");
  50.   gets(send_message);
  51.   puts("generating network name...");
  52.   send_block -> NCB_COMMAND = ADD_NAME_WAIT;
  53.   send_block -> NCB_LANA_NUM = 0;
  54.   send_block -> NCB_STO = 0;
  55.   send_block -> NCB_RTO = 0;
  56.   strncpy(send_block -> NCB_NAME, session, 16);
  57.   strncpy(send_block -> NCB_CALLNAME, "*", 16);
  58.   _ES = _DS;
  59.   _BX = send_block;
  60.   _AX = 0x100;
  61.   geninterrupt(0x5c);
  62.   ret_code = _AL;
  63.   net_num = send_block -> NCB_NUM;
  64.   if (ret_code)
  65.   {
  66.     printf("Bad return code = %02Xh\n", ret_code);
  67.     return;
  68.   }
  69.   printf("Session established. Name number = %02Xh\n", net_num);
  70.   puts("Sending datagram...");
  71.   send_block -> NCB_STO = 0;
  72.   send_block -> NCB_BUFFER_OFFSET = send_message;
  73.   send_block -> NCB_BUFFER_SEGMENT = _DS;
  74.   send_block -> NCB_LENGTH = strlen(send_message);
  75.   strncpy(send_block -> NCB_CALLNAME, rcvr, 16);
  76.   send_block -> NCB_COMMAND = SEND_DATAGRAM_WAIT;
  77.   _ES = _DS;
  78.   _BX = send_block;
  79.   _AX = 0x100;
  80.   geninterrupt(0x5c);
  81.   ret_code = _AL;
  82.   if (ret_code)
  83.     printf("Error number = %02Xh\n", ret_code);
  84.   else
  85.     puts("Datagram sent successfully.");
  86.   printf("Releasing session >>>%s<<<, name number %02Xh\n",
  87.     send_block -> NCB_NAME, net_num);
  88.   send_block -> NCB_NUM = net_num;
  89.   send_block -> NCB_COMMAND = DELETE_NAME_WAIT;
  90.   _ES = _DS;
  91.   _BX = send_block;
  92.   _AX = 0x100;
  93.   geninterrupt(0x5c);
  94.   ret_code = _AL;
  95.   if (ret_code)
  96.     printf("Error number = %02Xh.\n", ret_code);
  97.   else
  98.     puts("Completed normally.");
  99. }
  100.